freecivfandomcom-20200223-history
Forum:LUA script
I have almost done with concept proof for LUA ( http://www.lua.org/ ) to be used as a script for routine. I use it to help manage cities and going to use for more elaborated autoatack. API is in usable state now. But it still lacks fron end ;( ---- So, if there is any interest out there? Fedon :Hi Fedon, Sounds interesting alright. But I'm afraid you're inventing the wheel. As of Freeciv 2.1 the game is shipped with a Lua scripting framework. See for example the tutorial scenario, where this is used. On the other hand, with your Lua experience, I'm sure you'd be able to put it to good use in-game! We'd love to take a look at your city management and autoattack scripts, as they could probably be ported to the built-in framework! Best, Hima 23:19, 21 November 2007 (UTC) The matter is I play warciv. Its features are different from those of trunk version. One can see it from following short script I use to keep cities to rapture: if get_lux_level() > 10 then get_trade_cities() for i = 1, #cities do if get_city_size(citiesi) > 2 then v = generic_cma(citiesi) end end end By the way, I am not sure if scripts are needed at all in long term civ. --89.176.12.25 19:25, 23 November 2007 (UTC) Fedon For those who want to try ;) The only difference to the base code of pepclient 0.9.5 is --- /opt/warclient/freeciv-2.0/client/agents/agents.c 2007-07-05 03:49:31.000000000 +0200 +++ /opt/warclient/merged/client/agents/agents.c 2007-10-05 17:29:15.000000000 +0200 @@ -31,6 +31,7 @@ #include "cma_fec.h" #include "mapctrl_g.h" #include "sha.h" +#include "script.h" #include "agents.h" @@ -95,7 +96,7 @@ case OCT_TILE: return (pcall1->arg pcall2->arg); case OCT_NEW_TURN: - return TRUE; + return pcall1->agent pcall2->agent; } assert(0); @@ -346,6 +347,7 @@ /* Add init calls of agents here */ cma_init(); cmafec_init(); + script_init(); /*simple_historian_init();*/ } @@ -361,6 +363,7 @@ * for a simple disconnect and a client quit. for right now, we just * let the OS free the memory on exit instead of doing it ourselves. */ /* cmafec_free(); */ + script_free(); for (;;) { struct call *pcall = remove_and_return_a_call(); New files script.hc are attached. To build it one needs to install LUA 5.1 and make some changes to Makefiles. In agents Makefile variables libagents_a_SOURCES and am_libagents_a_OBJECTS should contain corresponding script.hco. Clients Makefile should contain LIBS = -lz -llua. Potential problems are - this source is not tested, I still looking for efficient unit management design. So, relevant code was removed but not tested then. But, I believe one who can use it can fix it if needed. - file names are fixed they are {$HOME}/.freeciv/script/raptur.bin and {$HOME}/.freeciv/script/work_list.bin; - some time caravan arrives late when scripts are done so one needs to utilaze extra money by hands. But it happens only once or twice per play; - most of methods are simple and selfexplanatory but generic_cma it uses settings from GUI CMA, so one needs to initiate them by calling the CMA window with desired setup. Unfortunately, I didn't find easy way to use CMA presets; - I use work_list script togather with work list presets (I have 6 or 8 of them) but it is not mandatory. Typical output for me is 5 turns i.e. plaing with hands and short timeout I lose 5 turns more than with script. But it is 2 turns latter than plaing with unlimited timeout still. --89.176.12.25 14:13, 2 December 2007 (UTC) Fedon